package com.mathdroid.model.enums;

import java.util.LinkedList;

import com.mathdroid.exceptionhandling.ParserException;

/**
 * The damage type of an ability or weapon.
 */
public enum EDmgType {

	/**
	 * Energy.
	 */
	ENERGY("Energy"),
	
	/**
	 * Elemental.
	 */
	ELEMENTAL("Elemental"),
	
	/**
	 * Elemental.
	 */
	PHYSICAL("Physical"),
	
	/**
	 * Kinetic (Tech & Force Damage).
	 */
	KINETIC("Kinetic"),
	
	/**
	 * Internal.
	 */
	INTERNAL("Internal");

	/**
	 * String representation of the type.
	 */
	private String name = null;
	
	/**
	 * Create a damage type enumeration.
	 * @param s String representation.
	 */
	EDmgType(final String s) {
		this.name = s;
	}
	
	@Override
	public String toString() {
		return this.name;
	}
	
	/**
	 * Get all available damage types as a list.
	 * @return All armor types.
	 */
	public static LinkedList<EDmgType> getAllTypes() {
		LinkedList<EDmgType> r = new LinkedList<EDmgType>();
		
		r.add(ENERGY);
		r.add(ELEMENTAL);
		r.add(PHYSICAL);
		r.add(KINETIC);
		r.add(INTERNAL);
		
		return r;
	}
	
	/**
	 * Parse a string to an enumeration object. The parser compares the
	 * string representation of this enumeration with the parameter, not the
	 * literal.
	 * @param s String.
	 * @return EDmgType object.
	 * @throws ParserException The string cannot be parsed.
	 */
	public static final EDmgType parseEDmgType(final String s) 
	throws ParserException {
		EDmgType a = null;
		
		for (EDmgType type : EDmgType.getAllTypes()) {
			if (s.equals(type.toString())) {
				a = type;
			}
		}
		
		if (a == null) {
			ParserException p = new ParserException(
					"No such damage type: \"" + s + "\"");
			p.fillInStackTrace();
			throw p;
		}
		
		return a;
	}
}
